<?php
/**
 * Created By PhpStorm
 * Author: patrick wu
 * Date: 2020/10/7
 * Time: 17:26
 */
namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Service\Api\IndexService;
use App\Constant\ErrorConstant;

class IndexController extends BaseController
{
    protected $service;

    public function __construct(Request $request, IndexService $service)
    {
        parent::__construct($request);
        $this->service  =   $service;
    }

    /**
     * 店铺模板展示
     * @return \Illuminate\Http\JsonResponse
     */
    public function showIndex()
    {
        [$flag, $result]    =   $this->service->indexShow();
        if ($flag) {
            return $this->successResponse($result);
        } else {
            return $this->errorResponse(ErrorConstant::API_INDEX_SHOW_ERROR, $result);
        }
    }

    /**
     * 个人中心页面
     * @return \Illuminate\Http\JsonResponse
     */
    public function personalIndex()
    {
        [$flag, $result]    =   $this->service->indexPersonal();
        if ($flag) {
            return $this->successResponse($result);
        } else {
            return $this->errorResponse(ErrorConstant::API_INDEX_PERSONAL_ERROR, $result);
        }
    }

    /**
     * 直播列表模板
     * @return \Illuminate\Http\JsonResponse
     */
    public function liveIndex()
    {
        [$flag, $result]    =   $this->service->indexLive();
        if ($flag) {
            return $this->successResponse($result);
        } else {
            return $this->errorResponse(ErrorConstant::API_INDEX_LIVE_ERROR, $result);
        }
    }

    /**
     * 支付结果模板
     * @return \Illuminate\Http\JsonResponse
     */
    public function payIndex()
    {
        [$flag, $result]    =   $this->service->indexPayResult();
        if ($flag) {
            return $this->successResponse($result);
        } else {
            return $this->errorResponse(ErrorConstant::API_INDEX_PAY_RESULT_ERROR, $result);
        }
    }

    /**
     * 购物车模板
     * @return \Illuminate\Http\JsonResponse
     */
    public function cartIndex()
    {
        [$flag, $result]    =   $this->service->indexCart();
        if ($flag) {
            return $this->successResponse($result);
        } else {
            return $this->errorResponse(ErrorConstant::API_INDEX_CART_ERROR, $result);
        }
    }

    /**
     * 会员招募模板内容
     * @return \Illuminate\Http\JsonResponse
     */
    public function recruitIndex()
    {
        [$flag, $result]    =   $this->service->indexRecruit();
        if ($flag) {
            return $this->successResponse($result);
        } else {
            return $this->errorResponse(ErrorConstant::API_INDEX_RECRUIT_ERROR, $result);
        }
    }
}
